package org.arain.spring.captive.portal.config;

import org.arain.spring.captive.portal.interceptor.Interceptor;
import org.arain.spring.captive.portal.utils.EhcacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 * @author Arain
 * @date 2019年6月28日 上午9:02:33
 */
@Configuration
public class WebConfiguraction implements WebMvcConfigurer {

	@Autowired
	private EhcacheUtil ehcacheUtil;
	
	/**
	 * 默认测试页面
	 */
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("redirect:/portal");
		registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
		WebMvcConfigurer.super.addViewControllers(registry);
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new Interceptor(ehcacheUtil)).addPathPatterns("/**").excludePathPatterns("/portal")
				.excludePathPatterns("/ext/**").excludePathPatterns("/p/**").excludePathPatterns("/login")
				.excludePathPatterns("/error");
	}

}